from sklearn.preprocessing import LabelEncoder
import label_encode
from sklearn.metrics import roc_auc_score, classification_report
import pandas as pd
import joblib

# 读取数据
data = pd.read_csv("../../data/raw/test2.csv")
# 数据预处理  将有多分类的列 转化为 数值型的
# 需要编码的列
cols = [
    "BusinessTravel", "Department", "Education", "EducationField",
    "EnvironmentSatisfaction", "Gender", "JobInvolvement", "JobLevel", "JobRole",
    "JobSatisfaction", "MaritalStatus", "OverTime", "PerformanceRating",
    "RelationshipSatisfaction", "TrainingTimesLastYear", "StockOptionLevel", "WorkLifeBalance"
]
data = label_encode.encode(data, cols)
# 提取特征和标签
X = data[["BusinessTravel",
          "Department",
          "EducationField",
          "EnvironmentSatisfaction",
          "JobInvolvement",
          "JobLevel",
          "JobRole",
          "JobSatisfaction",
          "MaritalStatus",
          "OverTime",
          "StockOptionLevel",
          "WorkLifeBalance",

          "DistanceFromHome",
          "Age",
          "YearsInCurrentRole",
          "YearsSinceLastPromotion",
          "MonthlyIncome",
          "PercentSalaryHike",
          "YearsWithCurrManager",
          "NumCompaniesWorked",
          "TotalWorkingYears",
          ]
]
scale = joblib.load('scale_model.pkl')
X = scale.transform(X)
y = data["Attrition"]

# 加载模型
model = joblib.load('xgb_model.pkl')
y_pred = model.predict_proba(X)[:, 1]

# 评估模型 AUC: 0.8711009465726447
print("AUC:", roc_auc_score(y, y_pred))
